const Router = require('koa-router');
const router = new Router();
const users = require('../models/users');

router.prefix('/users');


router.post('/login', async (ctx) => {
    const { username, password } = ctx.request.body;

    // 参数验证
    if (!username || !password) {
        ctx.status = 400;
        ctx.body = {
            status: 0,
            message: '用户名和密码不能为空'
        };
        return;
    }

    // 调用登录服务
    ctx.body = await users.login(username, password);
});

module.exports = router;